import {request} from '../utils/request'

const requestLogin = params => {
  
  return request('/api/user/login', params).then(data => {
  	localStorage.setItem('user-token', JSON.stringify(data.token))
  	return data
  })
}

const requestRegister = params => {
	return request('/api/user/register', params)
} 

const requestUserInfo = params => {
  return request('/api/user/info', params).then((data) => {
    sessionStorage.setItem('user-info', JSON.stringify(data))
    return data
  })
}

const requestLogout = params => {
  return request('/api/user/logout', params)
}

const requestChangePassword = params => {
  return request('/api/user/changePassword', params).then(data => {
    localStorage.setItem('user-token', JSON.stringify(data.token))
    return data
  })
}

const requestUserQuery = params => {
  return request('/api/user/query', params)
}

const requestPermissionsQuery = params => {
  return request('/api/user/permissions', params)
}



export {
	requestLogin,
	requestRegister,
	requestUserInfo,
  requestLogout,
  requestChangePassword,
  requestUserQuery,
  requestPermissionsQuery
}